import { getBaseURL, get, post, deletes } from "./request";
const HttpManager = {
  // 获取图片信息   后台数据包含/所以此处直接使用${url}而不是/${url}
  attachImageUrl: (url) =>
    url
      ? `${getBaseURL()}${url}`
      : "https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png",
  //获取所有的海报
  getBannerList: () => get("banner"),
  getAllSongList: () => get("songList?size=999&current=1"),

  // =======================> 评分 API 完成
  // 提交评分
  setRank: ({ songListId, consumerId, score }) =>
    post(`rankList/add`, { songListId, consumerId, score }),
  // 获取指定歌单的评分
  getRankOfSongListId: (songListId) => get(`rankList/songListId/${songListId}`),
  // 获取指定用户对指定歌单的评分
  getUserRank: (consumerId, songListId) =>
    get(`rankList/userRank?songListId=${songListId}&consumerId=${consumerId}`),
  // =======================> 歌单 API 完成
  // 获取全部歌单
  getSongList: () => get("song"),
  // 返回标题包含文字的歌单
  getSongListOfLikeTitle: (keywords) => get(`songList/like?title=${keywords}`),
  // 返回标题包含文字的歌单
  getSongListOfStyle: (style) => get(`songList/style/detail?style=${style}`),
  getSongsOfSongListId: (songListId) => get(`song/songList/${songListId}`),
  // =======================> 歌手 API  完成
  // 返回所有歌手
  getAllSinger: () => get("singer?size=100&current=1"),
  getSingerOfSex: (sex) => get(`singer?sex=${sex}`),

  // =======================> 歌曲 API
  // 返回指定歌手名的歌曲- 模糊查询
  getSongOfSingerName: (keywords) => get(`song/like?name=${keywords}`),
  getSongOfSingerId: (userId) => get(`/song/listBySingerId?id=${userId}`),
  // =======================> 用户 API
  // 用户登录
  signIn: ({ username, password }) =>
    post("user/login/status", { username, password }),
  // 用户注册
  SignUp: (user) => post("user/add", user),
  getUserOfId: (id) => get(`user/${id}`),
  // 用户主页收藏
  getCollectionOfUser: (id) => get(`collect?userId=${id}`),
  isCollection: (userId, type, songId) =>
    get(`collect/status?userId=${userId}&type=${type}&songId=${songId}`),
  setCollection: ({ userId, type, songId }) =>
    post(`collect/add`, { userId, type, songId }),
  deleteCollection: (userId, songId) =>
    post(`collect/delete`, { userId, "type": 0, songId }),
  getSongOfId: (id) => get(`song/detail?id=${id}`),
  // 更新用户信息
  updateUserMsg: ({
    id,
    username,
    sex,
    phoneNum,
    email,
    birth,
    introduction,
    location,
  }) =>
    post(`user/update`, {
      id,
      username,
      sex,
      phoneNum,
      email,
      birth,
      introduction,
      location,
    }),
  // 删除用户
  deleteUser: (id) => get(`user/delete?id=${id}`),
  // 更新用户头像
  uploadUrl: (userId) => `${getBaseURL()}/user/avatar/update?id=${userId}`,
  // 更新用户密码
  updateUserPassword: ({ id, username, oldPassword, password }) =>
    post(`user/updatePassword`, { id, username, oldPassword, password }),

  // 添加评论
  setComment: ({ userId, content, songId, songListId, type }) =>
    post(`comment/add`, { userId, content, songId, songListId, type }),
  // 删除评论
  deleteComment: (id) => deletes(`comment?idList=${id}`),
  // 返回所有评论
  getAllComment: (type, id) => {
    let url = "";
    if (type === 1) {
      url = `comment?songListId=${id}`;
    } else if (type === 0) {
      url = `comment?songId=${id}`;
    }
    return get(url);
  },

  //======================> 点赞api的优化 避免有些是重复的点赞
  testAlreadySupport: ({ commentId, userId }) =>
    post(`userSupport/test`, { commentId, userId }),

  deleteUserSupport: ({ commentId, userId }) =>
    post(`userSupport/delete`, { commentId, userId }),

  insertUserSupport: ({ commentId, userId }) =>
    post(`userSupport/insert`, { commentId, userId }),

  // 点赞
  setSupport: ({ id, up }) => post(`comment/like`, { id, up }),

  //=======================>购物车
  addCart: (songId, userId, price) =>
    post(`cart/add`, { songId, userId, price }),
  //获取当前用户购物车所有歌曲信息
  getCartList: (userId) => get(`cart/list?userId=${userId}`),
  //删除当前用户购物车中指定歌曲
  deleteCartList: (userId, delSongIds) =>
    get(`cart/remove?userId=${userId}&cartListIds=${delSongIds}`),
  // 歌曲是否支付
  getPaystatus: (songId, userId) =>
    get(`song/isPay?songId=${songId}&userId=${userId}`),
  // 支付歌曲费用
  toPay: (songIds, userId, payType) =>
    post(
      `pay/common/alipay?songIds=${songIds}&userId=${userId}&payType=${payType}`
    ),
};
export { HttpManager };
